//
//  YMTableViewCell.m
//  WFCoretext
//
//  Created by 阿虎 on 14/10/28.
//  Copyright (c) 2014年 tigerwf. All rights reserved.
// 2 3 2 2 2 3 1 3 2 1

#import "YMTableViewCell.h"
#import "WFReplyBody.h"
#import "ContantHead.h"
#import "YMTapGestureRecongnizer.h"
#import "WFHudView.h"
#import "SJAvatarBrowser.h"
#import "UIImageView+WebCache.h"
#import "WFActionSheet.h"
#import "WXViewController.h"
#define kImageTag 9999

@implementation YMTableViewCell
{
    UIButton *foldBtn;
    UIButton *deleteBtn;
    YMTextData *tempDate;
    UIImageView *replyImageView;
    UITableView *mainTable;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        // Initialization code
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor clearColor];
        //头像
        _userHeaderImage = [[UIImageView alloc] initWithFrame:CGRectMake(8, 10, 50, TableHeader)];
        _userHeaderImage.backgroundColor = [UIColor clearColor];
        CALayer *layer = [_userHeaderImage layer];
        [layer setMasksToBounds:YES];
        //[layer setCornerRadius:10.0];
        [layer setBorderWidth:0];
        //[layer setBorderColor:[[UIColor colorWithRed:61/255.0 green:121/255.0 blue:184/255.0 alpha:1.0] CGColor]];
        [self.contentView addSubview:_userHeaderImage];
        //用户名
        _userNameLbl = [[UILabel alloc] initWithFrame:CGRectMake(20+TableHeader , 10, screenWidth - 120, TableHeader/2)];
        _userNameLbl.textAlignment = NSTextAlignmentLeft;
        _userNameLbl.font = [UIFont systemFontOfSize:15.0];
        _userNameLbl.textColor = [UIColor colorWithRed:61/255.0 green:121/255.0 blue:184/255.0 alpha:1.0];
        [self.contentView addSubview:_userNameLbl];
        
        
        
        _imageArray = [[NSMutableArray alloc] init];
        _ymTextArray = [[NSMutableArray alloc] init];
        _ymShuoshuoArray = [[NSMutableArray alloc] init];
        _ymFavourArray = [[NSMutableArray alloc] init];
        
        //展开按钮
        foldBtn = [UIButton buttonWithType:0];
        [foldBtn setTitle:@"展开" forState:0];
        foldBtn.backgroundColor = [UIColor clearColor];
        foldBtn.titleLabel.font = [UIFont systemFontOfSize:15.0];
        [foldBtn setTitleColor:[UIColor grayColor] forState:0];
        [foldBtn addTarget:self action:@selector(foldText) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:foldBtn];
        
        
        replyImageView = [[UIImageView alloc] init];
        
        replyImageView.backgroundColor = [UIColor colorWithRed:242/255.0 green:242/255.0 blue:242/255.0 alpha:1.0];
        
        [self.contentView addSubview:replyImageView];
        //评论 赞 按钮
        _replyBtn = [YMButton buttonWithType:0];
        [_replyBtn setImage:[UIImage imageNamed:@"fw_r2_c2.png"] forState:0];
        [self.contentView addSubview:_replyBtn];

        
        //心形赞
        _favourImage = [[UIImageView alloc] initWithFrame:CGRectZero];
        _favourImage.image = [UIImage imageNamed:@"zan.png"];
        [self.contentView addSubview:_favourImage];
        //横线
        _hengxianImage = [[UIImageView alloc] initWithFrame:CGRectZero];
        _hengxianImage.image = [UIImage imageNamed:@"regist_line.png"];
        [self.contentView addSubview:_hengxianImage];
        
        deleteBtn = [UIButton buttonWithType:0];
        [deleteBtn setTitle:@"删除" forState:0];
        deleteBtn.backgroundColor = [UIColor clearColor];
        deleteBtn.titleLabel.font = [UIFont systemFontOfSize:12.0];
        deleteBtn.tag = 100;
        [deleteBtn setTitleColor:[UIColor grayColor] forState:0];
        
        [deleteBtn addTarget:self action:@selector(deleteShuoshuo:) forControlEvents:UIControlEventTouchUpInside];
        //[self.contentView addSubview:deleteBtn];
    }
    return self;
}

- (void)foldText{
    
    if (tempDate.foldOrNot == YES) {
        tempDate.foldOrNot = NO;
        [foldBtn setTitle:@"收起" forState:0];
    }else{
        tempDate.foldOrNot = YES;
        [foldBtn setTitle:@"展开" forState:0];
    }
    
    [_delegate changeFoldState:tempDate onCellRow:self.stamp];
    
}



-(void) deleteShuoshuo:(UIButton *)btn{
    NSLog(@"@@@@@@@@@@@@tag===%@",tempDate.messageBody.ssId);
    WFActionSheet *actionSheet = [[WFActionSheet alloc] initWithTitle:@"删除此说说吗？" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:nil, nil];
    actionSheet.actionIndex = 0 ;
    [actionSheet showInView:self];
//
}

- (void)actionSheet:(WFActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    NSLog(@"@@@@@@@@@@@@tag===%@",tempDate.messageBody.ssId);
    NSLog(@"@@@@@@@@@@@@tag===%ld",(long)buttonIndex);
    if (buttonIndex == 0) {
        //delete

        if (self.networkManager == nil) {
            self.networkManager = [[NetworkManager alloc] init];
        }
        NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:
                               tempDate.messageBody.ssId,@"ss_id",nil];
        [self.networkManager requestWithMethod:deleteShuoshuo parameter:param delegate:self];
       
        //mainTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, self.frame.size.width, self.frame.size.height - 84)];
  
        //[mainTable reloadData];
         //[self removeFromSuperview];
         //[self->mainTable reloadData];
        
    }else{
        
    }
//    _replyIndex = -1;
}


- (void)network:(NetworkManager *)net methodId:(RequestMethodId)methodId didRequestFinishedWithResult:(id)data {
    
    //[self endRefresh];
    //self.isRefreshing = NO;
    
    NSLog(@"@@@@@@@@@@@@@@@@1111111wzList");
    if (methodId == deleteShuoshuo) {
        //[self removeFromSuperview];
        //[self reloadInputViews];
        [_delegate deleteShuoshuo];
    }
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}


- (void)setYMViewWith:(YMTextData *)ymData{
    
     tempDate = ymData;
#pragma mark -  //头像 昵称 简介
  
    NSLog(@"@@@@@@@tempDate.messageBody.posterImgstr==%@",tempDate.messageBody.posterImgstr);
    
                NSURL *url1 = [NSURL URLWithString:tempDate.messageBody.posterImgstr];
          //      NSData *data1 = [NSData dataWithContentsOfURL:url1];
          //      UIImage *imageStr1 = [[UIImage alloc] initWithData:data1];
    
       // [_userHeaderImage setImage:imageStr1];
    
    
   // NSURL* imagePath1 = [NSURL URLWithString:@"http://s15.sinaimg.cn/middle/9914f9fdhbc6170891ebe&690"];
    
   // NSURL* imagePath2 = [NSURL URLWithString:@"http://s14.sinaimg.cn/middle/9914f9fdhbc611c219f3d&690"];
    
    //图片缓存的基本代码，就是这么简单
    [_userHeaderImage sd_setImageWithURL:url1];
    
    //用block 可以在图片加载完成之后做些事情
//    [self.image2 sd_setImageWithURL:imagePath2 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
//        
//        NSLog(@"这里可以在图片加载完成之后做些事情");
//        
//    }];
    //覆盖方法，指哪打哪，这个方法是下载imagePath2的时候响应
    SDWebImageManager *manager = [SDWebImageManager sharedManager];
    
    [manager downloadImageWithURL:url1 options:SDWebImageRetryFailed progress:^(NSInteger receivedSize, NSInteger expectedSize) {
        
        //NSLog(@"显示当前进度");
        
    } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
        //
        //NSLog(@"下载完成");
    }];
    
    //}
    UserInfo *user = [UserInfo instance];
    NSString * nickname = [[user.info objectForKey:@"nickname"] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    if(nickname == nil || [@"" isEqualToString:nickname]){
        nickname =[user.info objectForKey:@"username"];
    } else {
        nickname =[[user.info objectForKey:@"nickname"] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    }
    _userNameLbl.text = tempDate.messageBody.posterName;
    _userIntroLbl.text = tempDate.messageBody.posterIntro;
    //移除说说view 避免滚动时内容重叠
    for ( int i = 0; i < _ymShuoshuoArray.count; i ++) {
        WFTextView * imageV = (WFTextView *)[_ymShuoshuoArray objectAtIndex:i];
        if (imageV.superview) {
            [imageV removeFromSuperview];
        }
    }
    [_ymShuoshuoArray removeAllObjects];
#pragma mark - // /////////添加说说view
    WFTextView *textView = [[WFTextView alloc] initWithFrame:CGRectMake(offSet_X+ 170, TableHeader, screenWidth - 2 * offSet_X, 0)];
    //textView.delegate = self;
    textView.attributedData = ymData.attributedDataShuoshuo;
    textView.isFold = ymData.foldOrNot;
    textView.isDraw = YES;
    [textView setOldString:ymData.showShuoShuo andNewString:ymData.completionShuoshuo];
    [self.contentView addSubview:textView];
    
    BOOL foldOrnot = ymData.foldOrNot;
    float hhhh = foldOrnot?ymData.shuoshuoHeight:ymData.unFoldShuoHeight;
    
    textView.frame = CGRectMake(offSet_X+50, TableHeader-10, screenWidth - 2 * (offSet_X+35), hhhh);
    [_ymShuoshuoArray addObject:textView];
    //按钮
    foldBtn.frame = CGRectMake(offSet_X +40, 15 + TableHeader + hhhh -30 , 50, 20 ); 
    if (ymData.islessLimit) {//小于最小限制 隐藏折叠展开按钮
        foldBtn.hidden = YES;
    }else{
        foldBtn.hidden = NO;
    }
    if (tempDate.foldOrNot == YES) {
        [foldBtn setTitle:@"展开" forState:0];
    }else{
        
        [foldBtn setTitle:@"收起" forState:0];
    }
    
#pragma mark - /////// //图片部分
    for (int i = 0; i < [_imageArray count]; i++) {
        
        UIImageView * imageV = (UIImageView *)[_imageArray objectAtIndex:i];
        if (imageV.superview) {
            [imageV removeFromSuperview];
            
        }
        
    }
    
   [_imageArray removeAllObjects];
   NSLog(@"@@@@@@showImageArraycount===%lu",(unsigned long)[ymData.showImageArray count]);
   UIImageView *image ;
    for (int  i = 0; i < [ymData.showImageArray count]; i++) {
        
        NSArray *picsArray = [[ymData.showImageArray objectAtIndex:i] componentsSeparatedByString:@","];
        for(int j=0;j<[picsArray count];j++){
            
            if([picsArray objectAtIndex:j] != nil && ![[picsArray objectAtIndex:j] isEqualToString:@""]){
                NSLog(@"@@@@@@@@@image=====%@",image);
//                if(image == nil){
                    if(tempDate.foldOrNot == YES){
                        image =[[UIImageView alloc] initWithFrame:CGRectMake(((screenWidth)/4)*(j%4 ) + 1*(j%4)-12, TableHeader + 10 * ((j/4) + 1) + (j/4) *  ShowImage_H  + ymData.shuoshuoHeight + kDistance  + (ymData.islessLimit?0:30)-30, 78, 78)];
                    } else {
                        image =[[UIImageView alloc] initWithFrame:CGRectMake(((screenWidth)/4)*(j%4 ) + 1*(j%4)-12, TableHeader + 10 * ((j/4) + 1) + (j/4) *  ShowImage_H  + ymData.shuoshuoHeight + kDistance  + (ymData.islessLimit?0:30)-10, 78, 78)];
                    }
//                }
                image.userInteractionEnabled = YES;
               
                YMTapGestureRecongnizer *tap = [[YMTapGestureRecongnizer alloc] initWithTarget:self action:@selector(tapImageView:)];
                [image addGestureRecognizer:tap];
                tap.appendArray = ymData.showImageArray;
                image.backgroundColor = [UIColor clearColor];
                image.tag = kImageTag + j;

                //NSData *data1 = [NSData dataWithContentsOfURL:[NSURL URLWithString:[picsArray objectAtIndex:j] ]];
                NSURL *url1 = [NSURL URLWithString:[picsArray objectAtIndex:j]];
               // UIImage *imageStr1 = [[UIImage alloc] initWithData:data1];
                //[image setImage:imageStr1];
                //图片缓存的基本代码，就是这么简单
                [image sd_setImageWithURL:url1];
                
            
                
                //覆盖方法，指哪打哪，这个方法是下载imagePath2的时候响应
                SDWebImageManager *manager = [SDWebImageManager sharedManager];
                
                [manager downloadImageWithURL:url1 options:SDWebImageRetryFailed progress:^(NSInteger receivedSize, NSInteger expectedSize) {
                    
                   // NSLog(@"显示当前进度");
                    
                } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
                   // image.userInteractionEnabled = YES;
                   // NSLog(@"下载完成");
                }];
                
                
            }
            [self.contentView addSubview:image];
        }
        
        
        
    }
//    [image removeFromSuperview];
    [_imageArray removeAllObjects];
    
    
#pragma mark - /////点赞部分
    //移除点赞view 避免滚动时内容重叠
    for ( int i = 0; i < _ymFavourArray.count; i ++) {
        WFTextView * imageV = (WFTextView *)[_ymFavourArray objectAtIndex:i];
        if (imageV.superview) {
            [imageV removeFromSuperview];
            
        }
    }
    
    [_ymFavourArray removeAllObjects];
    
    
    float origin_Y = 10;
    NSUInteger scale_Y = ymData.showImageArray.count - 1;
    float balanceHeight = 0; //纯粹为了解决没图片高度的问题
    if (ymData.showImageArray.count == 0) {
        scale_Y = 0;
        balanceHeight = - ShowImage_H - kDistance ;
    }
    
    float backView_Y = 0;
    float backView_H = 0;

    WFTextView *favourView = [[WFTextView alloc] initWithFrame:CGRectMake(offSet_X + 30, TableHeader + 10 + ShowImage_H + (ShowImage_H + 10)*(scale_Y/3) + origin_Y + hhhh + kDistance + (ymData.islessLimit?0:30) + balanceHeight + kReplyBtnDistance-30, screenWidth - 2 * offSet_X , 0)];
    favourView.delegate = self;
    favourView.attributedData = ymData.attributedDataFavour;
    favourView.isDraw = YES;
    favourView.isFold = NO;
    favourView.canClickAll = NO;
    favourView.textColor = [UIColor colorWithRed:61/255.0 green:121/255.0 blue:184/255.0 alpha:1.0];

    // 赞列表
    [favourView setOldString:ymData.showFavour andNewString:ymData.completionFavour];
    favourView.frame = CGRectMake(offSet_X + 80,TableHeader + 10 + ShowImage_H + (ShowImage_H + 10)*(scale_Y/3) + origin_Y + hhhh + kDistance + (ymData.islessLimit?0:30) + balanceHeight + kReplyBtnDistance-30, screenWidth - offSet_X * 2 - 80, ymData.favourHeight);
    
    
    [self.contentView addSubview:favourView];
    backView_H += ((ymData.favourHeight == 0)?(-kReply_FavourDistance):ymData.favourHeight);
    
    
    [_ymFavourArray addObject:favourView];
    
    //心形赞图片的位置
    _favourImage.frame = CGRectMake(offSet_X + 55, favourView.frame.origin.y, (ymData.favourHeight == 0)?0:20,(ymData.favourHeight == 0)?0:20);
    
    
#pragma mark - ///// //最下方回复部分
    for (int i = 0; i < [_ymTextArray count]; i++) {
        
        WFTextView * ymTextView = (WFTextView *)[_ymTextArray objectAtIndex:i];
        if (ymTextView.superview) {
            [ymTextView removeFromSuperview];
            //  NSLog(@"here");
            
        }
        
    }
    
    [_ymTextArray removeAllObjects];
    NSLog(@"@@@@@@ymData.replyDataSource.count===%lu",(unsigned long)ymData.replyDataSource.count);
    NSLog(@"@@@@@@ymData.replyDataSource.count===%f",ymData.favourHeight);
    if( ymData.replyDataSource.count > 0 && ymData.favourHeight){
        NSLog(@"@@@@@@@YOUHENXIANG");
        _hengxianImage.frame = CGRectMake(offSet_X + 80,TableHeader + 10 + ShowImage_H + (ShowImage_H + 10)*(scale_Y/3) + origin_Y + hhhh + kDistance + (ymData.islessLimit?0:30) + balanceHeight + kReplyBtnDistance-30+backView_H-3, screenWidth - offSet_X * 2 - 80, 1);
        [self.contentView addSubview:_hengxianImage];
    } else {
        [_hengxianImage removeFromSuperview];
    }
  
    [_fabuDateLbl removeFromSuperview];
    
    if([ymData.showImageArray count] > 0 ){
        
        //        _fabuDateLbl = [[UILabel alloc] initWithFrame:CGRectMake(offSet_X  + 52,TableHeader + 10 + ShowImage_H + kDistance  + kReplyBtnDistance - 27+2, 120, 18)];
        NSLog(@"3333333333333333333");
        _fabuDateLbl = [[UILabel alloc] initWithFrame:CGRectMake(screenWidth - offSet_X - 230 ,TableHeader + 10 + ShowImage_H + (ShowImage_H + 10)*(scale_Y/3) + origin_Y + hhhh + kDistance + (ymData.islessLimit?0:30)+balanceHeight + kReplyBtnDistance - 65+9, 120, 14)];
        
        _fabuDateLbl.textAlignment = NSTextAlignmentLeft;
        _fabuDateLbl.font = [UIFont systemFontOfSize:12.0];
        _fabuDateLbl.textColor = [UIColor colorWithRed:61/255.0 green:121/255.0 blue:184/255.0 alpha:1.0];
        _replyBtn.frame = CGRectMake(screenWidth - offSet_X  -22,TableHeader + 10 + ShowImage_H + (ShowImage_H + 10)*(scale_Y/3) + origin_Y + hhhh + kDistance + (ymData.islessLimit?0:30)+balanceHeight + kReplyBtnDistance - 65+5, 41, 18)  ;
        
        if( tempDate.messageBody.isSelf == YES ){
            
            deleteBtn.frame = CGRectMake(screenWidth - offSet_X  -102,TableHeader + 10 + ShowImage_H + (ShowImage_H + 10)*(scale_Y/3) + origin_Y + hhhh + kDistance + (ymData.islessLimit?0:30)+balanceHeight + kReplyBtnDistance - 65+7, 36, 18) ;
            [self.contentView addSubview:deleteBtn];
        }else {
            [deleteBtn removeFromSuperview];
        }
    } else {
       _fabuDateLbl = [[UILabel alloc] initWithFrame:CGRectMake(screenWidth - offSet_X - 40 -191,TableHeader + 10 + ShowImage_H + (ShowImage_H + 10)*(scale_Y/3) + origin_Y + hhhh + kDistance + (ymData.islessLimit?0:30) + balanceHeight + kReplyBtnDistance - 65+9, 120, 14)];
//        _fabuDateLbl = [[UILabel alloc] initWithFrame:CGRectMake(screenWidth - offSet_X - 230 , replyImageView.frame.origin.y-20, 120, 14)];
       
        _fabuDateLbl.textAlignment = NSTextAlignmentLeft;
        _fabuDateLbl.font = [UIFont systemFontOfSize:12.0];
        _fabuDateLbl.textColor = [UIColor colorWithRed:61/255.0 green:121/255.0 blue:184/255.0 alpha:1.0];
        
        _replyBtn.frame = CGRectMake(screenWidth - offSet_X -22,TableHeader + 10 + ShowImage_H + (ShowImage_H + 10)*(scale_Y/3) + origin_Y + hhhh + kDistance + (ymData.islessLimit?0:30) + balanceHeight + kReplyBtnDistance - 65+5, 41, 18);
        
        if( tempDate.messageBody.isSelf == YES ){
            
            deleteBtn.frame = CGRectMake(screenWidth - offSet_X -102,TableHeader + 10 + ShowImage_H + (ShowImage_H + 10)*(scale_Y/3) + origin_Y + hhhh + kDistance + (ymData.islessLimit?0:30) + balanceHeight + kReplyBtnDistance - 65+7, 36, 18);
            [self.contentView addSubview:deleteBtn];
        }else {
            [deleteBtn removeFromSuperview];
        }
    }
    _fabuDateLbl.text= tempDate.messageBody.fabuDate;
    
    [self.contentView addSubview:_fabuDateLbl];
    
    
    for (int i = 0; i < ymData.replyDataSource.count; i ++ ) {
         WFTextView *_ilcoreText = [[WFTextView alloc] initWithFrame:CGRectMake(offSet_X+100,TableHeader + 10 + ShowImage_H + (ShowImage_H + 10)*(scale_Y/3) + origin_Y + hhhh + kDistance + balanceHeight + kReplyBtnDistance + ymData.favourHeight + (ymData.favourHeight == 0?0:kReply_FavourDistance)-400, screenWidth - offSet_X * 2-45, 0)];
        
        if (i == 0) {
            backView_Y = TableHeader + 10 + ShowImage_H + (ShowImage_H + 10)*(scale_Y/3) + origin_Y + hhhh + kDistance + (ymData.islessLimit?0:20);
        }
        
        _ilcoreText.delegate = self;
        _ilcoreText.replyIndex = i;
        _ilcoreText.isFold = NO;
        _ilcoreText.attributedData = [ymData.attributedDataReply objectAtIndex:i];
        
        
        WFReplyBody *body = (WFReplyBody *)[ymData.replyDataSource objectAtIndex:i];
        
        NSString *matchString;
        
        if ([body.repliedUser isEqualToString:@""]) {
            matchString = [NSString stringWithFormat:@"%@: %@",body.replyUser,body.replyInfo];
            
        }else{
            matchString = [NSString stringWithFormat:@"%@回复%@: %@",body.replyUser,body.repliedUser,body.replyInfo];
        }
        
        [_ilcoreText setOldString:matchString andNewString:[ymData.completionReplySource objectAtIndex:i]];
        //回复正文
          NSLog(@"@@@@@!!!!![_ilcoreText getTextHeight]@@@@%d",[_ilcoreText getTextLines]);
        NSLog(@"@@@@@[_ilcoreText getTextHeight]@@@@%f",[_ilcoreText getTextHeight]);
        _ilcoreText.frame =
        CGRectMake(offSet_X+55,TableHeader + 10 + ShowImage_H + (ShowImage_H + 10)*(scale_Y/3) + origin_Y + hhhh + kDistance + (ymData.islessLimit?0:30) + balanceHeight + kReplyBtnDistance + ymData.favourHeight + (ymData.favourHeight == 0?0:kReply_FavourDistance)-35, screenWidth - offSet_X * 2-45, [_ilcoreText getTextHeight]-4);
        [self.contentView addSubview:_ilcoreText];
        origin_Y += [_ilcoreText getTextHeight];
        
        backView_H += _ilcoreText.frame.size.height;
        
        [_ymTextArray addObject:_ilcoreText];
    }

    backView_H += (ymData.replyDataSource.count - 1)*5;
    
    [replyImageView removeFromSuperview];
   //13814313712
    NSLog(@"@@@@@tempDate.messageBody.posterName1111@@@@%@",tempDate.messageBody.posterName);
    if (ymData.replyDataSource.count == 0) {//没回复的时候
        NSLog(@"@@@@favourArray@@@@@%lu",(unsigned long)[ymData.completionFavour length]);
        NSLog(@"@@@@favourArray@@@@@%lu",(unsigned long)ymData.favourArray.count);
        if(ymData.favourArray.count > 0 && ![ymData.completionFavour isEqualToString:@""] && [ymData.completionFavour length] >0){
            replyImageView.frame = CGRectMake(offSet_X+50, _fabuDateLbl.frame.origin.y+20, screenWidth - offSet_X * 2-38,26);
//          replyImageView = [[UIImageView alloc] initWithFrame:CGRectMake(offSet_X+50 , _fabuDateLbl.frame.origin.y+20, screenWidth - offSet_X * 2-38, backView_H+10)];
            
        } else {
//            replyImageView = [[UIImageView alloc] initWithFrame:CGRectMake(screenWidth - offSet_X - 230 , _fabuDateLbl.frame.origin.y+20, screenWidth - offSet_X * 2-38, backView_H+10)];
//            NSLog(@"@@@@@@@@@@@@@@@@@@@@@@@@@@222222");
            replyImageView.frame = CGRectMake(offSet_X+50, _fabuDateLbl.frame.origin.y+20, screenWidth - offSet_X * 2-38,0);
            //[replyImageView removeFromSuperview];
            //[replyImageView removeFromSuperview];
            //[replyView removeFromSuperview];
            //replyImageView = nil;
        }
        
//        _replyBtn.frame = CGRectMake(screenWidth - offSet_X - 40 + 23-5,TableHeader + 10 + ShowImage_H + (ShowImage_H + 10)*(scale_Y/3) + origin_Y + hhhh + kDistance + (ymData.islessLimit?0:30) + balanceHeight + kReplyBtnDistance - 65+7, 36, 17);
        
        
    }else{
         NSLog(@"@@@@@@@@@@@@@@@@@@@@@@@@@@55555555%d",tempDate.foldOrNot==YES);
        NSLog(@"@@@@@@@@@@@@@@@@@@@@@@@@@@55555555%d",ymData.islessLimit==YES);

        
            if([ymData.showImageArray count] > 0){
                NSLog(@"@@@@@@@@@@@@@@@@@@@@@@@@@@444444444%f",hhhh);
//                if(ymData.islessLimit==YES){
//                    replyImageView.frame = CGRectMake(offSet_X+50, backView_Y - 10 + balanceHeight + 5 + kReplyBtnDistance+hhhh+(ymData.islessLimit?-8:5)-24*(hhhh/24+1), screenWidth - offSet_X * 2-38, backView_H+10);//微调
//                 } else {
                      replyImageView = [[UIImageView alloc] initWithFrame:CGRectMake(screenWidth - offSet_X - 230 , _fabuDateLbl.frame.origin.y+20, screenWidth - offSet_X * 2-38, backView_H+10)];
                     
//                     replyImageView.frame = CGRectMake(screenWidth - offSet_X - 40 -190,TableHeader + 10 + ShowImage_H + (ShowImage_H + 10)*(scale_Y/3) + origin_Y + hhhh + kDistance + (ymData.islessLimit?0:30) + balanceHeight + kReplyBtnDistance - 86, screenWidth - offSet_X * 2-38, backView_H+10);//微调
                     
//                 }
                
            } else {
//                if(ymData.islessLimit==YES){
//                    NSLog(@"@@@@@@@@@@@@@@@@@@@@@@@@@@3333333%f",hhhh);
//                    replyImageView.frame = CGRectMake(offSet_X+50, TableHeader +origin_Y - hhhh-15, screenWidth - offSet_X * 2 - 38, backView_H+10);//微调
//                } else {
//                    NSLog(@"@@@@@@@@@@@@@@@@@@@@@@@@@@666666%f",hhhh/24);
//                    replyImageView.frame = CGRectMake(screenWidth - offSet_X - 40 -190, origin_Y - 16*(hhhh/16+1), screenWidth - offSet_X * 2-38, backView_H+10);//微调
//                }
                
                replyImageView = [[UIImageView alloc] initWithFrame:CGRectMake(screenWidth - offSet_X - 40 -190, _fabuDateLbl.frame.origin.y+20, screenWidth - offSet_X * 2-38, backView_H+10)];
                
            }
        
//            _replyBtn.frame = CGRectMake(screenWidth - offSet_X - 23, replyImageView.frame.origin.y+
//                                         hhhh+(ymData.islessLimit?-27:-23)-20, 36, 17);
//           
//        } else {
//            NSLog(@"@@@@@@@@@@@@@@@@@@@@@@@@@@4444444");
//            replyImageView.frame = CGRectMake(offSet_X+50, backView_Y - 10 + balanceHeight + 5 + kReplyBtnDistance+hhhh+(ymData.islessLimit?-20:-90)-50, screenWidth - offSet_X * 2-42, backView_H+10);//微调
        
//            _replyBtn.frame = CGRectMake(screenWidth - offSet_X - 23, replyImageView.frame.origin.y+(ymData.islessLimit?-47:-23), 36, 17);
//        }
        }
    replyImageView.backgroundColor = [UIColor colorWithRed:242/255.0 green:242/255.0 blue:242/255.0 alpha:0.5];
    
    [self.contentView addSubview:replyImageView];

        //NSLog(@"@@@@@nickname@@@@%@",nickname);
        NSLog(@"@@@@@tempDate.messageBody.posterName@@@@%@",tempDate.messageBody.posterName);
    
 
    
    
}

#pragma mark - ilcoreTextDelegate
- (void)clickMyself:(NSString *)clickString{
    
    //延迟调用下  可去掉 下同
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:clickString message:nil delegate:nil cancelButtonTitle:@"好的" otherButtonTitles:nil, nil];
        [alert show];
        
        
    });
    
    
}


- (void)longClickWFCoretext:(NSString *)clickString replyIndex:(NSInteger)index{
    
    [_delegate longClickRichText:_stamp replyIndex:index];
    
}


- (void)clickWFCoretext:(NSString *)clickString replyIndex:(NSInteger)index{
    
    if ([clickString isEqualToString:@""]) {
        //reply
        //NSLog(@"reply");
        [_delegate clickRichText:_stamp replyIndex:index];
    }else{
        //do nothing
        [WFHudView showMsg:clickString inView:nil];
    }
    
}

#pragma mark - 点击action
- (void)tapImageView:(YMTapGestureRecongnizer *)tapGes{
    
    //[_delegate showImageViewWithImageViews:tapGes.appendArray byClickWhich:tapGes.view.tag];
   // NSLog(@"@@@@@@@@@@@tapGes.view==@@@@@%ld",(long)tapGes.view.tag);
        [SJAvatarBrowser showImage:tapGes.view];
    
    
    
}

@end
